{% extends "admin/layout.html" %}

{% block head %} 
<title>{{ _(config["WEBSITE_NAME"]) }} - {{ _("Settings") }}</title>
  {% if session["direction"] == "rtl" %}
    <style type="text/css">
      .list-unstyled {
        padding-right: 0;
      }
    </style>
  {% endif %}
{% endblock %}

{% block body %}
<div class="right_col" role="main" style="min-height: 939px;">
  <div class="">
    <div class="clearfix"></div>
    {% if get_flashed_messages() %}
      {% for error in get_flashed_messages() %}
          {% if error == "Error" %}
            <div class="alert alert-warning">
                <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
                <strong>{{ _("Warning!") }}</strong> {{ _("Couldn't upload selected files.") }}
            </div>
          {% elif error == "LangError" %}
            <div class="alert alert-warning">
                <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
                <strong>{{ _("Warning!") }}</strong> {{ _("Selected language isn't supported.") }}
            </div>
          {% elif errro == "Success" %}
            <div class="alert alert-success">
                <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
                <strong>{{ _("Upload Succeeded!") }}</strong> {{ _("Restart the platform before doing any other changes.") }}
            </div>            
          {% endif %}
      {% endfor %}
    {% endif %}

<div class="page-title">
  <div class="title_left">
    <h3>{{ _("Settings") }}</h3>
  </div>
</div>
    <div class="clearfix"></div>
    <div class="row">
      <div class="col-md-12">
        <div class="x_panel">
          <div class="x_content">
            <div class="row">                      
              <div class="clearfix"></div>
              <div class="clearfix"></div>
                <form method="POST" action="{{ url_for('admin.settings_config') }}" enctype="multipart/form-data">
                  <input name="_csrf_token" type="hidden" value="{{ csrf_token() }}">
                  <div class="form-group">
                      <label for="logo">{{ _("Logo:") }}</label>
                      <div class="input-group input-file" name="WEBSITE_LOGO" id="logo">
                          <input type="text" name="logo-text" class="form-control" value="{{ _(config['WEBSITE_LOGO']) }}" placeholder="{{ _('Choose a file...') }}">
                          <span class="input-group-btn">
                              <button class="btn btn-default btn-choose" type="button">{{ _("Choose") }}</button>
                          </span>
                      </div>
                  </div>
                  <div class="form-group">
                      <label for="favicon">{{ _("Favicon:") }}</label>
                      <div class="input-group input-file" id="favicon" name="FAVICON">
                          <input type="text" name="favicon-text" class="form-control" value="{{ _(config['FAVICON']) }}" placeholder="{{ _('Choose a file...') }}">
                          <span class="input-group-btn">
                              <button class="btn btn-default btn-choose" type="button">{{ _("Choose") }}</button>
                          </span>
                      </div>
                  </div>
                  <div class="form-group">
                      <label for="name">{{ _("Website Name:") }}</label>
                      <input type="text" required name="WEBSITE_NAME" id="name" value="{{ config['WEBSITE_NAME'] }}" class="form-control">
                  </div>
                  <div class="form-group">
                      <label for="footer">{{ _("Footer Content:") }}</label>
                      <input type="text" value="{{ config['FOOTER_MESSAGE'] }}" required name="FOOTER_MESSAGE" id="footer" class="form-control">
                  </div>
                  <div class="form-group">
                      <label for="lang">{{ _("Default Language:") }}</label>
                      <select style="text-align: left;" class="form-control" name="DEFAULT_LANGUAGE" id="lang">
                          {% for el in iso %}
                              {% if el.upper() == config["DEFAULT_LANGUAGE"] %}
                                  <option selected>{{ el }}</option>
                              {% else %}
                                  <option>{{ el }}</option>
                              {% endif %}
                          {% endfor %}
                      </select>
                  </div>
                  <input type="submit" value="{{ _('Submit') }}" class="btn btn-md btn-default">
              </form>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>
{% endblock %}

{% block footer %}
<script type="text/javascript">
  function bs_input_file() {
      $(".input-file").before(
          function() {
              if ( ! $(this).prev().hasClass("input-ghost") ) {
                  var element = $("<input type='file' class='input-ghost' style='visibility:hidden; height:0'>");
                  element.attr("name",$(this).attr("name"));
                  element.change(function(){
                      element.next(element).find("input").val((element.val()).split("\\").pop());
                  });
                  $(this).find("button.btn-choose").click(function(){
                      element.click();
                  });
                  $(this).find("button.btn-reset").click(function(){
                      element.val(null);
                      $(this).parents(".input-file").find("input").val("");
                  });
                  $(this).find("input").css("cursor","pointer");
                  $(this).find("input").mousedown(function() {
                      $(this).parents(".input-file").prev().click();
                      return false;
                  });
                  return element;
              }
          }
      );
  }
  $(function() {
      bs_input_file();
  });
</script>
{% endblock %}